// pages/exchange/exchange.js
const App = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    oerderNumber: '',
    showDialog: false,
    tipsText: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },
  onCloseDialog() {
    this.setData({
      showDialog: false,
    })
  },
  async exchangeTimes() {
    let { oerderNumber } = this.data;
    //oerderNumber = `3213119313951852544`
    // oerderNumber = `3213130695402325248`
    if (!oerderNumber) {
      this.setData({
        tipsText: '您尚未输入订单编号',
        showDialog: true,
      })
      return
    }
    try {
      App.showLoading();
      let {
        data
      } = await App.$http("/api/front/exchangeTimes", {
        oerderNumber
      });
      this.setData({
        tipsText: '完成兑换',
        showDialog: true,
      });
      wx.setStorageSync('ischange', 1);
      wx.hideLoading();
    } catch (error) {
      let estr = error.toString();
      this.setData({
        tipsText: estr=='[Object Object]'?'登录状态已过期，请到“我的”页面退出账号再次登录兑换。':error.toString(),
      },() => {
        this.setData({showDialog: true,})
      });
      wx.hideLoading();
    }
  }
})